﻿using System;
using fastCSharp;

namespace diantou.web.exam
{
    /// <summary>
    /// 企业考试
    /// </summary>
    [fastCSharp.code.cSharp.webView(IsPool = true, IsReferer = false)]
    partial class index : view<index>
    {
        /// <summary>
        /// 
        /// </summary>
        /// <returns></returns>
        private bool loadView(int examId, bool isPreview)
        {
            if (isPreview)
            {
                diantou.dataAccess.user user = pub.GetSessionUser(this);
                if (user != null && user.IsEnterprisePermission)
                {
                    exam = diantou.examDataAccess.clientCache.Exam[examId];
                    if (exam == null) AjaxResponse(webConfig.NotFound404);
                    else
                    {
                        if (user.Id == exam.UserId) return true;
                        AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = diantou.dataModel.path.pub.EnterpriseLogin });
                    }
                }
                else AjaxResponse(new fastCSharp.code.cSharp.webView.errorPath { ErrorPath = diantou.dataModel.path.pub.EnterpriseLogin });
                return false;
            }
            if (base.user != null && examUser.ExamId == examId)
            {
                if (examUser.IsRegister)
                {
                    if (examUser.ExamTime != fastCSharp.pub.MinTime && !examUser.IsSubmit && examUser.SubmitTime > date.NowSecond)
                    {
                        location(new diantou.dataModel.path.exam { Id = examId }.Problem);
                    }
                    else location(new diantou.dataModel.path.exam { Id = examId }.Description);
                }
                else location(new diantou.dataModel.path.exam { Id = examId }.Setting);
                return false;
            }
            if (load(examId))
            {
                switch (exam.Type)
                {
                    case dataModel.exam.type.考生熟悉环境的测试赛: 
                    case dataModel.exam.type.完成答卷后发简历的考试:
                    case dataModel.exam.type.预先注册的考试:
                        location(exam.Path.Register); 
                        return false;
                }
                return true;
            }
            return false;
        }
    }
}
